<!--
 * @Author: yao
 * @Date: 2025-01-29 02:31:49
 * @LastEditTime: 2025-02-18 17:29:18
 * @LastEditors: yao
 * @Description: 
 * @FilePath: \jdev-web-el\src\components\Dock\FlatMenu.vue
-->
<template>
  <div class="flat_menu">
    <div v-for="(menu, index) in menus" :key="index" class="menu-column"
      :style="{ 'margin-left': `${menu.level * 10}px` }">

      <div class="content" v-if="menu.isLeaf && menu.meta.type === 'menu'">
        <div class="content_link" :title="menu.meta.title" @click="toMenu(menu)">{{ menu.meta.title }}</div>
        <el-icon style="font-size: 18px;cursor: pointer;color:#E6A23C" v-if="menu.fav"
          @click.native="favEvent(false, menu)">
          <StarFilled />
        </el-icon>
        <el-icon style="cursor: pointer;padding-right: 2px;" v-else @click.native="favEvent(true, menu)">
          <Star />
        </el-icon>
      </div>
      <div v-else>
        <el-divider v-if="index > 0" color="#DCDFE6"></el-divider>
        <div class="title" :title="menu.meta.title">{{ menu.meta.title }}</div>
      </div>
    </div>
  </div>

</template>

<script setup lang='ts'>

import { useUserStore } from '@/stores/modules/user';
import { useRouter } from 'vue-router';
const emit = defineEmits(['favEvent']);
const props = defineProps({
  menus: {
    type: Array<any>,
    default: []
  }
})
const router = useRouter();
const useUser = useUserStore();
const favEvent = (isFav: boolean, menu: any) => {
  emit('favEvent', isFav, menu)
}
const toMenu = (val) => {
  router.replace(`${val.path || ''}`);
}
</script>

<style lang='scss'>
.flat_menu {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  flex-direction: column;
  gap: 2px;
  height: 100%;
  align-content: flex-start;

  .menu-column {
    padding: 0 4px;
    width: 200px;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    font-size: 18px;
    margin-right: 60px;

    .ep-divider--horizontal {
      margin: 16px 0;
    }

    .title {
      font-size: 1rem;
      font-weight: 400;
      border-radius: 8px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      color: #303133;
      width: max-content;
      max-width: 200px;
      margin-bottom: 6px;
    }

    .content {
      font-size: 0.9rem;
      margin-bottom: 2px;
      width: 100%;
      color: #606266;
      box-sizing: border-box;
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 10px;

      .content_link {
        padding: 4px 8px;
        transition: all .3s;
        cursor: pointer;
        width: 100%;
        border-radius: 6px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;

        &:hover {
          color: #409eff;
          background: rgba(64, 158, 255, .1);
        }
      }

    }
  }
}
</style>